package net.xiduth.tools;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import net.xiduth.game.item.Item;
import net.xiduth.game.player.Player;
import net.xiduth.utils.SerializableFilesManager;

/**
 * 
 * @author Kova+
 *
 */

public class CheckAccount {
	
	public static int[] ITEMS = { 19479, 1038, 1040, 1042, 1044, 1046, 1048 };
	
	public static void main(String[] args)  {
		File dir = new File("./data/characters/");
		File[] accs = dir.listFiles();
		for (File acc : accs) {
			Player player = null;
			try {
				player = (Player) SerializableFilesManager.loadSerializedFile(acc);
				if (player == null) {
					continue;
				}
				File pickUpLogs = new File("data/text.txt");
				try {
					if (player == null) 
						continue;
					BufferedWriter writer = new BufferedWriter(new FileWriter(pickUpLogs, true));
					System.out.println("Done " + acc.getName());
					writer.write(" ----- " + acc.getName() + " ----- ");
					for (int i = 0; i < 7; i++) {
						if (player.getBank().containsItem(ITEMS[i], 5)) {
							Item item = player.getBank().getItem(ITEMS[i]);
							if (item == null)
								continue;
							writer.write(item.getName() + " " + item.getAmount());
							writer.newLine();
						}
					}
					for (int i = 0; i < 7; i++) {
						if (player.getInventory().containsItem(ITEMS[i], 1)) {
							int amount = player.getInventory().getNumerOf(ITEMS[i]);
							Item item = new Item(ITEMS[i]);
							if (item == null)
								continue;
							writer.write(item.getName() + " " + amount);
							writer.newLine();
						}
					}
					writer.write("----------");
					writer.newLine();
					writer.flush();
					writer.close();	
				} catch (IOException e) {
					e.printStackTrace();
				}
			} catch (ClassNotFoundException | IOException e) {
				e.printStackTrace();
			}
			try {
				SerializableFilesManager.storeSerializableClass(player, acc);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
